package com.yidu.DailyFinalTreatment.service.impl;


import com.yidu.DailyFinalTreatment.entity.CashInventMo;
import com.yidu.DailyFinalTreatment.mapper.CashInventMoMapper;
import com.yidu.DailyFinalTreatment.service.CashInventMoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

@Service
public class CashInventMoImpl implements CashInventMoService {

    @Autowired
    private CashInventMoMapper cashInventMapper;


    @Override
    public List<CashInventMo> selectCashinvent(String date) {
        Map map =new HashMap();
        if (date!=null && !date.equals("")){
            map.put("date","cashInventorysTime="+date(date));
        }else {
            map.put("date","1=1");
        }
        return cashInventMapper.selectCashinvent(map);
    }

    public String date(String date)  {
        SimpleDateFormat sj = new SimpleDateFormat("yyyy-MM-dd");
        if (date!=null && !date.equals("")){
            Date da = null;
            try {
                da = sj.parse(date);
                System.out.println("da="+da);
            } catch (ParseException e) {
                e.printStackTrace();
            }
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(da);
            calendar.add(calendar.DATE,0);
            System.out.println("昨天" + sj.format(calendar.getTime()));
            return "'"+sj.format(calendar.getTime())+"'";
        }else {
            return "0000-00-00";
        }
    }
}
